package progarm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Map;

public class MovieFind {


	String find(String movieId,Map map){//movie-user
		String key = movieId;
		String userlist="";
		if(map.containsKey(key)){
			String value = (String) map.get(key);
			String[] usergourp=value.split("\\|");
			for(String userId : usergourp){
				String[] moviegourp=userId.split(",");
				userlist+=moviegourp[0]+" ";
			}
			return userlist;
		}else{
			return "no exist!";
		}
	}
	String nextFind_list(String list,Map map){//movie-user-movie
		ArrayList<String> checklist = new ArrayList<String>();

		if (list == "no exist!") {
			return list;
		} else {
			String[] str = list.split(" ");
			list="";
			for (String userid : str) {
				
				if (map.containsKey(userid)) {
					//System.out.println("user:" + userid);
					String value = (String) map.get(userid);
					String[] moviegourp = value.split("\\|");
					//int c1=0;int c2=0;
					for (String movieid : moviegourp) {
						//System.out.println("user:" + movieid);
						String[] movie = movieid.split(",");
						//System.out.println("user:" + movie[0]);
						//c1++;
						if (!checklist.contains(movie[0])) {
							//c2++;
							checklist.add(movie[0]);
							list += movie[0] + "|";
						}
					}
					//System.out.println(c1+" "+c2);
				}
			}
		}
		return list;
	}
}
